package com.partner.partnerback.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.partner.partnerback.common.Constants;
import com.partner.partnerback.common.Result;
import com.partner.partnerback.entity.User;
import com.partner.partnerback.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 程序员曾庆红
 * @since 2023-04-12
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private IUserService userService;

    @GetMapping
    public Result findAll(){

        return Result.success(userService.list());
    }
    @GetMapping("/{id}")
    public Result getById(@PathVariable int id){
        return Result.success(userService.getById(id));
    }

    /**
     * 新增
     * @param user
     * @return
     */
    @PostMapping
    public Result save(@RequestBody User user){

        userService.save(user);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody User user){
        userService.updateById(user);
        return Result.success();
    }

}
